package com.zzj.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zzj.bean.InboxBean;
import com.zzj.dao.AssembleDao;
import com.zzj.dao.InboxDao;
import com.zzj.utils.Result;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class InboxServiceImpl implements InboxService {
    @Resource
    private InboxDao inboxDao;
    @Resource
    private AssembleDao assembleDao;

    @Override
    public PageInfo<InboxBean> findAll(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<InboxBean> all = inboxDao.findAll();
        return new PageInfo<>(all);
    }

    @Override
    public Result addInbox(InboxBean inboxBean) {
        // 给选择的组装表的状态改为3
        // 循环添加装箱表
        List<String> nums = inboxBean.getNums();
        for (String num : nums) {
            assembleDao.updateStateByAnum(num,"3");
            inboxBean.setAnum(num);
            inboxBean.setIstate("0");
            inboxDao.addInbox(inboxBean);
        }
        return new Result();
    }
}
